<?php

if (!$l_loged) {
    include "login_error.php";
} else { if ($l_role < 3) {
        include "role_error.php";
    } else {
        ?>
<h2 class="cont_page">Přidání nového uživatele</h2>

<?PHP
if (isset($_POST['adduser_btn']) && (($_POST['add_username'] != '') && ($_POST['add_pass'] != '') && ($_POST['add_mail'] != '') && ($_POST['add_tel'] != ''))) {
    if (!user_ctrl($_POST['add_username'])){
        echo('<p class="err_desc">Zadali jste uživatelské jméno, které již v systému je!!</p>');
    } else {
    if (user_add($_POST['add_username'], $_POST['add_pass'], $_POST['add_name'], $_POST['add_mail'], $_POST['add_tel'], $_POST['add_icq'], $_POST['add_adress'])) {
       echo('<p class="ok_desc">Přidání nového uživatele proběhlo úspěšně..</p><br><br>');
    } else {
        echo ('<p class="err_desc">Chyba při vkládání !!</p>');
    }
}
}

?>

<form action="adduser.php" method="post" id="form_usr" name="form_usr">
    <fieldset  class="user">
        <legend>Nový uživatel</legend>
        <p <?PHP if (isset($_POST['adduser_btn']) && ($_POST['add_username'] == '')) {echo ('class="err_form"');} else {echo ('class="ok_form"');} ?>>
            <label for="add_username" class="nes">*Username:</label>
            <input maxlength="50" value="<?php echo htmlspecialchars($_POST['add_username']);?>" type="text" id="add_username" name="add_username">
        </p>

        <p <?PHP if (isset($_POST['adduser_btn']) && ($_POST['add_name'] == '')) {echo ('class="err_form"');} else {echo ('class="ok_form"');} ?>>
            <label for="add_name" class="nes">*Jmeno: </label>
            <input maxlength="50" type="text" value="<?php echo htmlspecialchars($_POST['add_name']);?>" id="add_name" name="add_name">
        </p>

        <p <?PHP if (isset($_POST['adduser_btn']) && ($_POST['add_pass'] == '')) {echo ('class="err_form"');} else {echo ('class="ok_form"');} ?>>
            <label for="add_pass" class="nes">*Heslo: </label>
            <input type="text" maxlength="20" value="<?php echo htmlspecialchars($_POST['add_pass']);?>" id="add_pass" name="add_pass">
        </p>
        <p <?PHP if (isset($_POST['adduser_btn']) && ($_POST['add_mail'] == '')) {echo ('class="err_form"');} else {echo ('class="ok_form"');} ?>>
            <label for="add_mail" class="nes">*Mail: </label>
            <input type="text" maxlength="100" value="<?php echo htmlspecialchars($_POST['add_mail']);?>" id="add_mail" name="add_mail"> (pokud nema, napis nema!)
        </p>

        <p <?PHP if (isset($_POST['adduser_btn']) && ($_POST['add_tel'] == '')) {echo ('class="err_form"');} else {echo ('class="ok_form"');} ?>>
            <label for="add_tel" class="nes">*Tel:</label>
            <input type="text" maxlength="9" value="<?php echo htmlspecialchars($_POST['add_tel']);?>" id="add_tel" name="add_tel"> (pokud nema, napis nema!)
        </p>
        <p class="ok_form">
            <label for="add_icq">Icq: </label>
            <input type="text" maxlength="20" value="<?php echo htmlspecialchars($_POST['add_icq']);?>" id="add_icq" name="add_icq">
        </p>
        <p class="ok_form">
            <label for="add_adress">Adresa: </label>
            <input type="text" size="70" maxlength="100" value="<?php echo htmlspecialchars($_POST['add_adress']);?>" id="add_adress" name="add_adress">
        </p>    <?PHP if (isset($_POST['adduser_btn']) && (($_POST['add_username'] == '') || ($_POST['add_pass'] == '') || ($_POST['add_mail'] == '') || ($_POST['add_tel'] == ''))) {echo ('<p class="err_desc">* Všechny prvky touto barvou je nutné vyplnit!</p>');} ?>
    <p>
        <input class="btn" type="submit" value="vytvořit" id="adduser_btn" name="adduser_btn">
    </p>
    </fieldset>


</form>

<script type="text/javascript">
    var form = document.getElementById('form_usr');
    form.onsubmit = ctrl_usr;

    function ctrl_usr(){
        var jmeno = document.getElementById('add_username');
        var add_pass = document.getElementById('add_pass');
        var add_name = document.getElementById('add_name');
        var add_mail = document.getElementById('add_mail');
        var add_tel = document.geatelementById('add_tel');

        if (jmeno.value == ''){
            alert('Chybí vypln\u011bné uživatelské jméno!');
            return(true);
        }
        if (add_name.value == ''){
            alert('Chybí vypln\u011bné jméno!');
            return(true);
        }
        if (add_mail.value == ''){
            alert('Chybí vypln\u011bné add_mail!');
            return(true);
        }
        if (add_pass.value == ''){
            alert('Chybí vypln\u011bné heslo!');
            return(true);
        }

        if (add_tel.value == ''){
            alert('Chybí vypln\u011bné add_tel!');
            return(true);
        }
        return(true);
    }
</script>


    <?php
}
}
?>
